package simulator;

import java.util.Collections;
import java.util.LinkedList;

public class SlidingWindow extends LinkedList<Data>{

	private static final long serialVersionUID = 1L;
	private int W;
	
	public SlidingWindow(int W) {
		this.W = W;
	}

	@Override
	public boolean add(Data e) {
		boolean add = super.add(e);
		Collections.sort(this);
		return add;
	}

	public boolean isFull() {
		return this.size() == W;
	}
	
	public int windowSize() {
		return W;
	}
	
	public String toString() {
		String str = "";
		for (Data d : this) {
			str += "[" + d.getID() + "]";
		}
		return "size: " + this.size() + "\n" + str;

	}
	
}
